package com.jwaoo.chat.session.audio;

import com.dx.as.common.string.StringUtil;
import com.jwaoo.chat.Message;
import com.jwaoo.chat.session.audioplayer.Playable;

public class AudioMessagePlayable implements Playable {

	private Message message;

	public Message getMessage() {
		return message;
	}

	public AudioMessagePlayable(Message playableMessage) {
		this.message = playableMessage;
	}

	@Override
	public long getDuration() {
		return message.getAttachment().getDuration();
	}

	@Override
	public String getPath() {
		String path = message.getAttachment().getPath();
		return StringUtil.isEmpty(path) ? message.getAttachment().getUrl() : path;
	}

	@Override
	public boolean isAudioEqual(Playable audio) {
		if (AudioMessagePlayable.class.isInstance(audio)) {
			return message.isTheSame(((AudioMessagePlayable) audio).getMessage());
		} else {
			return false;
		}
	}
}
